package com.exam.Controller;

import com.exam.Entity.ApiResult;
import com.exam.Entity.MultipleQuestion;
import com.exam.Service.MultipleQuestionService;
import com.exam.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class MultipleQuestionController {

    @Autowired
    private MultipleQuestionService multipleQuestionService;
    @GetMapping("/multipleQuestionId")
    public ApiResult findOnlyQuestion() {
        MultipleQuestion res = multipleQuestionService.findOnlyQuestionId();
        return ApiResultHandler.buildApiResult(200,"查询成功",res);
    }

    @DeleteMapping("/question/multipleQuestion/{id}")
    public ApiResult delete(@PathVariable("id") Integer id) {
        int res = multipleQuestionService.deleteById(id);
        if (res != 0) {
            return ApiResultHandler.buildApiResult(200, "删除成功", res);
        }
        return ApiResultHandler.buildApiResult(400, "删除失败，题目不存在或已被删除", res);
    }

    @PostMapping("/MultipleQuestion")
    public ApiResult add(@RequestBody MultipleQuestion multipleQuestion) {
        int res = multipleQuestionService.add(multipleQuestion);
        if (res != 0) {

            return ApiResultHandler.buildApiResult(200,"添加成功",res);
        }
        return ApiResultHandler.buildApiResult(400,"添加失败",res);
    }
}
